package com.dhcc.bpm.modules.safe.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhcc.bpm.common.text.Convert;
import com.dhcc.bpm.modules.safe.entity.AppGateway;
import com.dhcc.bpm.modules.safe.mapper.AppGatewayMapper;
import com.dhcc.bpm.modules.safe.service.IAppGatewayService;
import com.dhcc.bpm.modules.safe.vo.AppGatewayVO;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName AppGatewayServiceImpl
 * @Description 网关访问控制渠道关联表 服务实现类
 * @Author daina
 * @Date 2020/2/21 14:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 */
@Service("opc_app_gateway")
public class AppGatewayServiceImpl extends ServiceImpl<AppGatewayMapper, AppGateway> implements IAppGatewayService {

	@Override
	public IPage<AppGatewayVO> selectAppGatewayPage(IPage<AppGatewayVO> page, AppGatewayVO appGateway) {
		return page.setRecords(baseMapper.selectAppGatewayPage(page, appGateway));
	}

	@Override
	public Boolean batchControllerApp(Long opcControlId, String ids) {
		List<Long> appIds = Func.toLongList(ids);
		ArrayList<AppGateway> list = new ArrayList<>();
		appIds.forEach(appId->{
			AppGateway appGateway = new AppGateway();
			appGateway.setOpcAppId(appId);
			appGateway.setOpcControlId(opcControlId);
			list.add(appGateway);
		});
		return saveBatch(list);
	}

	@Override
	public int deleteApps(Long opcControlId, String ids) {
		return baseMapper.deleteApps(opcControlId,Convert.toLongArray(ids));
	}
}
